import request from '../utils/request'

// 教师登录
export function teacherLogin(teNo, password) {
  return request({
    url: '/teacher-user/login',
    method: 'post',
    params: { teNo, password }
  })
}

// 获取教师个人信息
export function getTeacherInfo(teacherId) {
  return request({
    url: `/teacher-user/info/${teacherId}`,
    method: 'get'
  })
}

// 更新教师个人信息
export function updateTeacherInfo(teacher) {
  return request({
    url: '/teacher-user/update',
    method: 'put',
    data: teacher
  })
}

// 获取教师课表
export function getTeacherSchedule(teacherId, semester) {
  // 统一走后端兜底接口：当学期无数据时由后端自动回退 advanced -> 2025-1
  return request({
    url: `/teacher-user/schedule/${teacherId}`,
    method: 'get',
    params: { semester: semester || '' }
  })
}

// 获取教师本周课表
export function getTeacherWeekSchedule(teacherId, semester, weekNo) {
  return request({
    url: `/teacher-user/schedule/week/${teacherId}/${semester}/${weekNo}`,
    method: 'get'
  })
}

// 获取教师今日课表
export function getTeacherTodaySchedule(teacherId, semester, weekNo, dayOfWeek) {
  return request({
    url: `/teacher-user/schedule/today/${teacherId}/${semester}/${weekNo}/${dayOfWeek}`,
    method: 'get'
  })
}

// 申请调课
export function applyScheduleChange(scheduleId, reason, newTimeSlotId, newClassroomId) {
  return request({
    url: '/teacher-user/schedule/change',
    method: 'post',
    data: { scheduleId, reason, newTimeSlotId, newClassroomId }
  })
}

// 获取教师工作量统计
export function getTeacherWorkloadStats(teacherId, semester) {
  return request({
    url: `/teacher-user/workload/${teacherId}/${semester}`,
    method: 'get'
  })
}

// 获取教师时间偏好
export function getTeacherTimePreference(teacherId) {
  return request({
    url: `/teacher-user/preference/${teacherId}`,
    method: 'get'
  })
}

// 设置教师时间偏好
export function setTeacherTimePreference(teacherId, preferences) {
  return request({
    url: `/teacher-user/preference/${teacherId}`,
    method: 'post',
    data: preferences
  })
}

// 获取教师的学生列表
export function getTeacherStudents(teacherId, semester) {
  return request({
    url: `/teacher-user/students/${teacherId}/${semester}`,
    method: 'get'
  })
}

// ==================== 成绩管理 API ====================

// 获取教师的成绩列表
export function getTeacherGrades(teacherId, params) {
  return request({
    url: `/teacher-user/grades/${teacherId}`,
    method: 'get',
    params: params // { semester, courseId, clazzId, studentName, status }
  })
}

// 获取教师的课程列表
export function getTeacherCourses(teacherId, semester) {
  return request({
    url: `/teacher-user/courses/${teacherId}`,
    method: 'get',
    params: { semester }
  })
}

// 获取课程的班级列表
export function getCourseClasses(teacherId, courseId, semester) {
  return request({
    url: `/teacher-user/course/${courseId}/classes`,
    method: 'get',
    params: { teacherId, semester }
  })
}

// 获取班级的学生列表
export function getClassStudents(clazzId, courseId) {
  return request({
    url: `/teacher-user/class/${clazzId}/students`,
    method: 'get',
    params: { courseId }
  })
}

// 添加成绩
export function addGrade(gradeData) {
  return request({
    url: '/teacher-user/grade/add',
    method: 'post',
    data: gradeData
  })
}

// 更新成绩
export function updateGrade(gradeData) {
  return request({
    url: '/teacher-user/grade/update',
    method: 'put',
    data: gradeData
  })
}

// 删除成绩
export function deleteGrade(gradeId) {
  return request({
    url: `/teacher-user/grade/delete/${gradeId}`,
    method: 'delete'
  })
}

// 批量添加成绩
export function batchAddGrades(gradesData) {
  return request({
    url: '/teacher-user/grade/batch-add',
    method: 'post',
    data: gradesData
  })
}

// 导出成绩
export function exportGrades(teacherId, params) {
  return request({
    url: `/teacher-user/grades/export/${teacherId}`,
    method: 'get',
    params: params,
    responseType: 'blob'
  })
}

// ==================== 选课审核相关 ====================

// 获取待审核的选课申请列表
export function getPendingCourseApplications(teacherId, semester) {
  return request({
    url: `/teacher-user/course-applications/pending/${teacherId}`,
    method: 'get',
    params: { semester }
  })
}

// 审核选课申请
export function reviewCourseApplication(studentCourseId, approved, rejectReason) {
  return request({
    url: '/teacher-user/course-applications/review',
    method: 'post',
    params: {
      studentCourseId,
      approved,
      rejectReason
    }
  })
}








